package dirindex;

import gate.*;
import gate.creole.*;

public class AnniPipe {

	/**
	 * @param args
	 */
	
	private static SerialAnalyserController annieController;
	
	public AnniPipe(int iiLang) {
		//System.out.println("Initialising ANNIE...");
		  try {
			  final String PR_NAMES_RPOST [] = 
			  {
			          "gate.creole.annotdelete.AnnotationDeletePR",
			          "gate.creole.tokeniser.DefaultTokeniser",
			          "gate.creole.splitter.SentenceSplitter"
			  };			  
		     
		// create a serial analyser controller to run ANNIE with
			  annieController =
			        (SerialAnalyserController) Factory.createResource(
			          "gate.creole.SerialAnalyserController", Factory.newFeatureMap(),
			          Factory.newFeatureMap(), "ANNIE_" + Gate.genSym()
			        );
		      // load each PR as defined in ANNIEConstants
		      for(int i = 0; i < PR_NAMES_RPOST.length; i++) {
		        FeatureMap params = Factory.newFeatureMap(); // use default parameters
		        ProcessingResource pr = (ProcessingResource)
		          Factory.createResource(PR_NAMES_RPOST[i], params);
		  
		        // add the PR to the pipeline controller
		        annieController.add(pr);
		      }
		      FeatureMap params = Factory.newFeatureMap();
	          params.put("portLemServer", "8002");
	          params.put("hostLemServer", "192.168.0.29");	          if (iiLang == 1)
	        	  params.put("dictLemServer", "RUSSIAN");	          else	        	  params.put("dictLemServer", "ENGLISH");	      
	          ProcessingResource pr = (ProcessingResource)
	            Factory.createResource("russian.RuPOSTagger", params);
	  
	          // add the PR to the pipeline controller
	          annieController.add(pr);
			  params = null;
			  pr = null;
			  //Factory = null;

		  } catch ( Exception e ) { System.out.println(e); }
	}
	
	public void execute() {
		try {
	      //System.out.println("Running ANNIE...");
	      annieController.execute();
	      //annieController = null;
	      //System.out.println("...ANNIE complete");
	      
		} catch ( Exception e ) { System.out.println(e); }
	}
	
	public void setCorpus(Corpus corpus) 
	{
		  annieController.setCorpus(corpus);
	}


	public void close() 
	{
	      annieController = null;
	      
	}

}
